package presentacion;

import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;

import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JTabbedPane;


import java.awt.BorderLayout;
import java.awt.TextField;
import java.awt.Point;
import java.awt.Button;
import java.awt.ComponentOrientation;
import java.io.File;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.Color;


public class GUIPrincipal extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JMenuBar jJMenuBar = null;
	private JMenu MenuArchivo = null;
	private JMenuItem jMenuItemNuevo = null;
	private JMenuItem jMenuItemAbrir = null;
	private JTabbedPane jTabbedPane = null;
	private JPanel jPanelCaptura = null;
	private JPanel jPanelXML = null;
	private TextField textFieldRutaImagen = null;
	private Button buttonAbrir = null;
	private Button buttonExaminar = null;
	private JPanel panelImagen = null;
	private JPanel jPanelCreaZonas = null;
	private JPanel jPanelCrearNuevaZona = null;
	private JPanel jPanelZonasCreadas = null;
	/**
	 * This is the default constructor
	 */
	public GUIPrincipal() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(1132, 689);
		this.setLocation(new Point(100, 100));
		this.setResizable(true);
		this.setJMenuBar(getJJMenuBar());
		this.setContentPane(getJContentPane());
		this.setTitle("Por ahora JFrame");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.insets = new Insets(0, 0, 1, 1);
			gridBagConstraints1.fill = GridBagConstraints.BOTH;
			gridBagConstraints1.gridy = 0;
			gridBagConstraints1.gridwidth = 2;
			gridBagConstraints1.weightx = 3.0;
			gridBagConstraints1.weighty = 3.0;
			gridBagConstraints1.anchor = GridBagConstraints.NORTHWEST;
			gridBagConstraints1.gridx = 1;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
			gridBagConstraints.fill = GridBagConstraints.BOTH;
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			gridBagConstraints.weightx = 2.0;
			gridBagConstraints.weighty = 2.0;
			gridBagConstraints.insets = new Insets(1, 1, 2, 0);
			jContentPane = new JPanel();
			jContentPane.setLayout(new GridBagLayout());
			jContentPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
			jContentPane.add(getJTabbedPane(), gridBagConstraints);
			jContentPane.add(getJPanelCreaZonas(), gridBagConstraints1);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jJMenuBar	
	 * 	
	 * @return javax.swing.JMenuBar	
	 */
	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.setPreferredSize(new Dimension(20, 20));
			jJMenuBar.add(getMenuArchivo());
		}
		return jJMenuBar;
	}

	/**
	 * This method initializes MenuArchivo	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getMenuArchivo() {
		if (MenuArchivo == null) {
			MenuArchivo = new JMenu();
			MenuArchivo.setText("Archivo");
			MenuArchivo.add(getJMenuItemNuevo());
			MenuArchivo.add(getJMenuItemAbrir());
		}
		return MenuArchivo;
	}

	/**
	 * This method initializes jMenuItemNuevo	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItemNuevo() {
		if (jMenuItemNuevo == null) {
			jMenuItemNuevo = new JMenuItem();
		}
		jMenuItemNuevo.setText("Nuevo");
		return jMenuItemNuevo;
	}

	/**
	 * This method initializes jMenuItemAbrir	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItemAbrir() {
		if (jMenuItemAbrir == null) {
			jMenuItemAbrir = new JMenuItem();
		}
		jMenuItemAbrir.setText("Abrir");
		return jMenuItemAbrir;
	}

	/**
	 * This method initializes jTabbedPane	
	 * 	
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			jTabbedPane.setTabPlacement(JTabbedPane.TOP);
			jTabbedPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
			
			jTabbedPane.addTab("Captura", null, getJPanelCaptura(), null);
			jTabbedPane.addTab("XML", null, getJPanelXML(), null);
		}
		return jTabbedPane;
	}

	/**
	 * This method initializes jPanelCaptura	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelCaptura() {
		if (jPanelCaptura == null) {
			GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
			gridBagConstraints5.insets=new Insets(5,5,5,5);
			gridBagConstraints5.gridy = 1;
			gridBagConstraints5.gridx = 2;
			gridBagConstraints5.ipadx = 5;
			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
			gridBagConstraints4.insets = new Insets(5,5,5,5);
			gridBagConstraints4.gridy = 1;
			gridBagConstraints4.gridx = 1;
			gridBagConstraints4.ipadx=40;
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.insets=new Insets(5,5,5,5);
			gridBagConstraints3.gridx = 0;
			gridBagConstraints3.gridy = 1;
			gridBagConstraints3.weightx = 0.1;
			gridBagConstraints3.fill=GridBagConstraints.HORIZONTAL;
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.gridx = 0;
			gridBagConstraints2.gridy = 0;
			gridBagConstraints2.gridwidth = 3;
			gridBagConstraints2.fill = GridBagConstraints.BOTH;
			gridBagConstraints2.weighty = 0.5;
			jPanelCaptura = new JPanel();
			jPanelCaptura.setLayout(new GridBagLayout());
			jPanelCaptura.add(getPanelImagen(), gridBagConstraints2);
			jPanelCaptura.add(getTextFieldRutaImagen(), gridBagConstraints3);
			jPanelCaptura.add(getButtonAbrir(), gridBagConstraints4);
			jPanelCaptura.add(getButtonExaminar(), gridBagConstraints5);
		}
		return jPanelCaptura;
	}

	/**
	 * This method initializes jPanelXML	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelXML() {
		if (jPanelXML == null) {
			jPanelXML = new JPanel();
			jPanelXML.setLayout(null);
		}
		return jPanelXML;
	}

	/**
	 * This method initializes textFieldRutaImagen	
	 * 	
	 * @return java.awt.TextField	
	 */
	private TextField getTextFieldRutaImagen() {
		if (textFieldRutaImagen == null) {
			textFieldRutaImagen = new TextField();
		}
		return textFieldRutaImagen;
	}

	/**
	 * This method initializes buttonAbrir	
	 * 	
	 * @return java.awt.Button	
	 */
	private Button getButtonAbrir() {
		if (buttonAbrir == null) {
			buttonAbrir = new Button();
			buttonAbrir.setLabel("Abrir");
			buttonAbrir.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("Abrir"); 
					JLabel label=new JLabel();
					ImageIcon escena = new ImageIcon(textFieldRutaImagen.getText());
					panelImagen.add(label);
					label.setIcon(escena);
											    
				}
			});
		}
		return buttonAbrir;
	}

	/**
	 * This method initializes buttonExaminar	
	 * 	
	 * @return java.awt.Button	
	 */
	private Button getButtonExaminar() {
		if (buttonExaminar == null) {
			buttonExaminar = new Button();
			buttonExaminar.setLabel(" Examinar ");
			buttonExaminar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("Examinar"); // TODO Auto-generated Event stub actionPerformed()
					JFileChooser fileChooser= new JFileChooser();
					int seleccion = fileChooser.showOpenDialog(buttonAbrir);
					if (seleccion == JFileChooser.APPROVE_OPTION)
					{
					   File fichero = fileChooser.getSelectedFile();
					   JLabel label=new JLabel();
					   panelImagen.add(label, BorderLayout.CENTER);
					   panelImagen.add(label);
					   label.setIcon(new ImageIcon (fichero.getAbsolutePath()));
					   
					   
					
					}
				}
			});
		}
		return buttonExaminar;
	}

	/**
	 * This method initializes panelImagen	
	 * 	
	 * @return java.awt.Panel	
	 */
	private JPanel getPanelImagen() {
		if (panelImagen == null) {
			panelImagen = new JPanel();
			panelImagen.setLayout(new BorderLayout());	
		}
		return panelImagen;
	}

	/**
	 * This method initializes jPanelCreaZonas	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelCreaZonas() {
		if (jPanelCreaZonas == null) {
			GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
			gridBagConstraints7.insets = new Insets(5,5,5,5);
			gridBagConstraints7.weightx=1.0;
			gridBagConstraints7.weighty=1.0;
			gridBagConstraints7.gridx = 0;
			gridBagConstraints7.gridy = 1;
			gridBagConstraints7.fill = GridBagConstraints.BOTH;
			gridBagConstraints7.anchor = GridBagConstraints.NORTHWEST;
			GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
			gridBagConstraints6.insets = new Insets(5,5,5,5);
			gridBagConstraints6.weighty=1.0;
			gridBagConstraints6.weightx=2.0;
			gridBagConstraints6.gridx = 0;
			gridBagConstraints6.gridy = 0;
			gridBagConstraints6.fill = GridBagConstraints.BOTH;
			gridBagConstraints6.anchor = GridBagConstraints.NORTHWEST;
			jPanelCreaZonas = new JPanel();
			jPanelCreaZonas.setLayout(new GridBagLayout());
			jPanelCreaZonas.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
			jPanelCreaZonas.add(getJPanelCrearNuevaZona(), gridBagConstraints6);
			jPanelCreaZonas.add(getJPanelZonasCreadas(), gridBagConstraints7);
		}
		return jPanelCreaZonas;
	}

	/**
	 * This method initializes jPanelCrearNuevaZona	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelCrearNuevaZona() {
		if (jPanelCrearNuevaZona == null) {
			jPanelCrearNuevaZona = new JPanel();
			jPanelCrearNuevaZona.setLayout(new GridBagLayout());
			jPanelCrearNuevaZona.setBorder(BorderFactory.createTitledBorder(null, "Crear nueva zona", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
			jPanelCrearNuevaZona.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
		}
		return jPanelCrearNuevaZona;
	}

	/**
	 * This method initializes jPanelZonasCreadas	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelZonasCreadas() {
		if (jPanelZonasCreadas == null) {
			jPanelZonasCreadas = new JPanel();
			jPanelZonasCreadas.setLayout(new GridBagLayout());
			jPanelZonasCreadas.setBorder(BorderFactory.createTitledBorder(null, "Zonas creadas", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
		}
		return jPanelZonasCreadas;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
